package kr.hkit.powerjava.chapter22.dpt;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class DepartmentMeneger implements ItemDaoInterface<Department> {
	Map<Department, Department> dm = new HashMap<Department, Department>();

	public DepartmentMeneger(Map<Department, Department> dm) {
		this.dm = dm;
	}

	@Override
	public void addItem(Department key, Department value) {
		dm.put(key, value);
	}

	@Override
	public void delItem(Department k) {
		if (searchItem(k)) {
			dm.remove(dm.get(k));
		} else {
			System.out.println("fail");
		}
	}

	@Override
	public void updateItem(Department k, Department v) {
		if (searchItem(k)) {
			dm.put(k, v);
		} else {
			System.out.println("fail");
		}
	}

	@Override
	public boolean searchItem(Department k) {
		return dm.containsKey(k);
	}

	public void searchItems(Department keyDpt) {
		if (searchItem(keyDpt)) {
			System.out.println("검색한 값 : " + dm.get(keyDpt) + "   <<<<< 삭제!");
		} else {
			System.out.println("fail");
		}
	}

	@Override
	public void prnItem() {
		for (Entry<Department, Department> s : dm.entrySet()) {
			System.out.printf("%s\n", s.getValue());
		}
	}

	public void prnHeader() {
		String str = String.format("%s\t %s\t %s", "번호", "이름", "강의실");
		System.out.println(str);
		System.out.println("-------------------");
	}

}
